<?php

namespace app\admin\model;

use think\Model;


class Orderstore extends Model
{

    

    

    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_pay_text',
        'pay_type_text',
        'pay_time_text',
        'type_text',
        'status_text',
        'source_type_text'
    ];
    

    
    public function getIsPayList()
    {
        return ['0' => __('未支付'), '2' => __('已支付')];
    }

    public function getPayTypeList()
    {
        return ['1' => __('微信'), '2' => __('支付宝'), '3' => __('云闪付'), '4' => __('pos机'), '5' => __('现金')];
    }

    public function getTypeList()
    {
        return ['1' => __('充值订单'), '2' => __('油品订单'), '3' => __('商品订单')];
    }

    public function getStatusList()
    {
        return ['0' => __('交易'), '2' => __('取消')];
    }

    public function getSourceTypeList()
    {
        return ['1' => __('小程序'), '2' => __('PC')];
    }


    public function getIsPayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_pay']) ? $data['is_pay'] : '');
        $list = $this->getIsPayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSourceTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['source_type']) ? $data['source_type'] : '');
        $list = $this->getSourceTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setPayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
